package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.hqfinance.domain.HqCostSubject;
import com.ruoyi.hqfinance.domain.HqReturnTransferFeeCollect;
import com.ruoyi.hqfinance.domain.HqReturnTransferFeeDetail;
import com.ruoyi.hqfinance.domain.vo.HqReturnTransferFeeCollectVo;
import com.ruoyi.hqfinance.domain.vo.HqReturnTransferFeeDetailVo;
import com.ruoyi.hqfinance.service.HqCostSubjectService;
import com.ruoyi.hqfinance.service.HqReturnTransferFeeDetailService;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/returnTransferFee")
@Api(tags = "总部财务-退件中转费报表")
public class HqReturnTransferFeeDetailController {
    @Autowired
    private HqReturnTransferFeeDetailService hqReturnTransferFeeDetailService;

    @ApiOperation("查全部")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate) {
        List<HqReturnTransferFeeDetail> details = hqReturnTransferFeeDetailService.selectAll(pageDate);
        if (details == null || details.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(details));
        }
    }

    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody HqReturnTransferFeeDetail hqReturnTransferFeeDetail){
        Boolean isAdd = hqReturnTransferFeeDetailService.insert(hqReturnTransferFeeDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody HqReturnTransferFeeDetail hqReturnTransferFeeDetail){
        Boolean isUpdate = hqReturnTransferFeeDetailService.update(hqReturnTransferFeeDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R delete(Integer id){
        Boolean isDelete = hqReturnTransferFeeDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody HqReturnTransferFeeDetailVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null || vo.getIsShare() == null){
            return R.fail("请输入查询所需的必要条件！");
        }
        List<HqReturnTransferFeeDetail> details = hqReturnTransferFeeDetailService.search(vo);
        if (details == null || details.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(details));
        }
    }

    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody HqReturnTransferFeeCollectVo vo) {
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getNetworkNameId() == null ){
            return R.fail("请输入查询所需的必要条件！");
        }
        List<HqReturnTransferFeeCollect> collects = hqReturnTransferFeeDetailService.collect(vo);
        if (collects == null || collects.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(collects));
        }
    }
}


